package com.lm.elastic.service;


import com.lm.elastic.model.Article;
import com.lm.elastic.repository.ArticleRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleService {

    private final ArticleRepository repository;

    public ArticleService(ArticleRepository repository) {
        this.repository = repository;
    }

    public Article save(Article article) {
        return repository.save(article);
    }

    public Iterable<Article> findAll() {
        return repository.findAll();
    }

    public List<Article> searchByTitle(String keyword) {
        return repository.findByTitleContaining(keyword);
    }

    public List<Article> findByAuthor(String author) {
        return repository.findByAuthor(author);
    }
}
